Improve file open error when packaging crates
authorAlex Crichton <alex@alexcrichton.com>
Tue, 26 Jul 2016 19:55:10 +0000 (12:55 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 26 Jul 2016 23:29:20 +0000 (16:29 -0700)
Be sure to point to the file in question.

Closes #2914

src/cargo/ops/cargo_package.rs
tests/package.rs

index 8201a5fa867368d5dd8c89bf9c6684963cdc5e2f..4e6ae0a9d71b27b3449754213dd0b616d19f30b4 100644 (file)
@@ -185,7 +185,9 @@ fn tar(ws: &Workspace,
             human(format!("non-utf8 path in source directory: {}",
                           relative.display()))
         }));
-        let mut file = try!(File::open(file));
+        let mut file = try!(File::open(file).chain_error(|| {
+            human(format!("failed to open for archiving: `{}`", file.display()))
+        }));
         try!(config.shell().verbose(|shell| {
             shell.status("Archiving", &relative)
         }));
index 129b6d243f8b41630b490a9438bcec60d11879ff..b953c3916c69bc4ace396f1e521a3faeb7a5aaa9 100644 (file)
@@ -1,3 +1,4 @@
+#[macro_use]
 extern crate cargotest;
 extern crate flate2;
 extern crate git2;
@@ -466,3 +467,39 @@ fn repackage_on_source_change() {
     }).collect::<Vec<PathBuf>>();
     assert_that(&entry_paths, contains(vec![PathBuf::from("foo-0.0.1/src/foo.rs")]));
 }
+
+#[test]
+#[cfg(unix)]
+fn broken_symlink() {
+    use std::os::unix::fs;
+
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            license = "MIT"
+            description = 'foo'
+            documentation = 'foo'
+            homepage = 'foo'
+            repository = 'foo'
+        "#)
+        .file("src/main.rs", r#"
+            fn main() { println!("hello"); }
+        "#);
+    p.build();
+    t!(fs::symlink("nowhere", &p.root().join("src/foo.rs")));
+
+    assert_that(p.cargo("package").arg("-v"),
+                execs().with_status(101)
+                       .with_stderr_contains("\
+error: failed to prepare local package for uploading
+
+Caused by:
+  failed to open for archiving: `[..]foo.rs`
+
+Caused by:
+  [..]
+"));
+}